package com.hualan.sfzy.service.system.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.system.Permission;
import com.hualan.sfzy.mapper.system.PermissionMapper;
import com.hualan.sfzy.service.system.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName PermissionServiceImpl
 * @Description TODO
 * @Author Mindy
 * @Date 2025年07月12日 下午2:59
 * @Version 1.0
 */
@Service("permissionService")
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public int add(Permission permission) {
        return permissionMapper.insert(permission);
    }

    @Override
    public int remove(Integer id) {
        return permissionMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return permissionMapper.deleteBatch(ids);
    }

    @Override
    public int edit(Permission permission) {
        return permissionMapper.update(permission);
    }

    @Override
    public Permission findById(Integer id) {
        return permissionMapper.selectById(id);
    }

    @Override
    public Map<String, Object> findByPage(Integer pageNum, Integer pageSize, Permission permission) {

        PageHelper.startPage(pageNum, pageSize);

        List<Permission> list = permissionMapper.select(permission);

        PageInfo<Permission> pageInfo = new PageInfo<>(list);

        Map<String, Object> map = new HashMap<>();

        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());

//        map.put("list", list);
//        map.put("total", pageInfo.getTotal());
//        map.put("pages", pageInfo.getPages());

        return map;
    }

    @Override
    public List<Permission> find() {
        return permissionMapper.select(null);
    }
}
